import cv2
import pyzbar.pyzbar as pyzbar
# import zbar
 
 
def detect():
    camera = cv2.VideoCapture(0)
    while True:
        ret, frame = camera.read()
 
        barcodes = pyzbar.decode(frame)
 
        data = ''

        for barcode in barcodes:
            data = barcode.data.decode('utf-8')
        if data != '':
            with open('data.txt', 'w') as file:
                file.write(data)
            break
        if cv2.waitKey(1) == ord('q'):
            break
        cv2.imshow('', frame)
    camera.release()
    cv2.destroyAllWindows()
 

detect()
